package com.xcdh.ittools.service.impl;

import com.api.ittools.entity.Tables;
import com.api.ittools.entity.TablesColumn;
import com.xcdh.ittools.mapper.metadata.mysql.MysqlColumnMapper;
import com.xcdh.ittools.mapper.metadata.mysql.MysqlTableMapper;
import com.xcdh.ittools.service.MataDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * MysqlMataDataServiceImpl
 * Created by wjg on 2024/4/22.
 */
@Service("mysqlMataDataService")
public class MysqlMataDataServiceImpl implements MataDataService {
    @Autowired
    private MysqlTableMapper tableMapper ;
    @Autowired
    private MysqlColumnMapper columnMapper ;

    @Override
    public Tables getTable(String database, String tableName) {
        Tables tables = Tables.builder().tableName(tableName).dataBaseName(database).build();
        Tables result = tableMapper.queryTables(tables).get(0);
        List<TablesColumn> tableColumns = columnMapper.getTableColumns(tables);
        result.setColumns(tableColumns);
        return result;
    }
}
